package ModeratorOperations;

import CRUD.BanHome;
import CRUD.SuspendHome;

import java.util.Iterator;
import java.util.List;
import xmlMapping.Ban;
import xmlMapping.Member;
import xmlMapping.Suspend;
/**
 *
 * @author sh
 */
public class ModeratorManageUser {
    public void BanneUser(Ban ban) {
        BanHome home =new BanHome();
        home.persist(ban);
    }

    public void unBanneUser(int mId) {
         BanHome home =new BanHome();
        Ban ban=home.findById(mId);
        home.delete(ban);
    }

    public void suspendUser(Suspend suspend) {
        SuspendHome home=new SuspendHome();
        home.persist(suspend);
    }

    public void unSuspendUser(int userid) {
        SuspendHome home=new SuspendHome();
        Suspend sus=new Suspend();
        Member mem=new Member();
        mem.setMemberId(userid);
        sus.setMemberByMemberId(mem);
       Iterator i= home.findByExample(sus).iterator();
       home=new SuspendHome();
           java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
       while(i.hasNext()){
           Suspend suspend=(Suspend)i.next();
           if(suspend.getExpiredate().after(sqlDate)){
               suspend.setExpiredate(sqlDate);
               home.attachDirty(suspend);
           }
       }

    }
//    public static void main(String [] args){
//        ModeratorManageUser modmanage=new ModeratorManageUser();
//        //////////////ban/////////
//        Ban ban=new Ban();
//        ban.setDatebanned(new Date());
//        ban.setReason("because u ......");
//        Member mm=new Member();
//        mm.setMemberId(2);
//        ban.setMemberByMemberId(mm);
//        Member mem=new Member();
//        mem.setMemberId(1);
//        ban.setMemberByModId(mem);
//        modmanage.BanneUser(ban);
//        //////unban////////////////
//        //modmanage.unBanneUser(2);
//        //////////unsuspend///////
//        //modmanage.unSuspendUser(3);
//        //////////////////suspend/////////////
////        Suspend sus=new Suspend();
////        Member mem=new Member();
////        mem.setMemberId(3);
////        sus.setMemberByMemberId(mem);
////        Member mod=new Member();
////        mod.setMemberId(1);
////        sus.setMemberByModId(mod);
////        sus.setReason("sdfsdsdsds");
////        sus.setExpiredate(new Date(111,4,12));
////        modmanage.suspendUser(sus);
//    }
}
